package com.myrent.utils;

import java.security.SecureRandom;

/**
 * 密码的加密
 */
public class SaltUtil {

    static final char[] CODE_SEQUENCE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890".toCharArray();
    static final int SALT_LENGTH = 8;
    private static final int ENCRYPT_NUM = 21;

    /**加密次数8  */
    public static int getEncryptNum() {
        return ENCRYPT_NUM;
    }

    /**
     * 产生随机盐值
     */
    public static String produceSalt() {
        StringBuilder randomString = new StringBuilder();
        SecureRandom random = new SecureRandom();
        for (int i = 0; i < SALT_LENGTH; i++) {
            String strRand = String.valueOf(CODE_SEQUENCE[random.nextInt(62)]);
            randomString.append(strRand);
        }
        return randomString.toString();
    }


}
